package com.leyou.item.dto;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CategoryTwoLevelDTO {

    private Long id;
    private String name;
    private List<CategorySubDTO> categorySubDTO;

    public CategoryTwoLevelDTO(Long id, String name, List<CategorySubDTO> categorySubDTO) {
        this.id = id;
        this.name = name;
        this.categorySubDTO = categorySubDTO;
    }

    public CategoryTwoLevelDTO() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<CategorySubDTO> getCategorySubDTO() {
        return categorySubDTO;
    }

    public void setCategorySubDTO(List<CategorySubDTO> categorySubDTO) {
        this.categorySubDTO = categorySubDTO;
    }

    public static List<CategoryTwoLevelDTO> ofDTOs(List<Category> levelTwo, Map<Long,List<Category>> subDTOs) {

        return levelTwo.stream().map(x->{
            return new CategoryTwoLevelDTO(x.getId(),x.getName(),CategorySubDTO.ofDTOs(subDTOs.get(x.getId())));
        }).collect(Collectors.toList());
    }

}
